home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / RxSlides / RxSlides.c < prev    next >
C/C++ Source or Header  |  1990-03-08  |  8KB  |  414 lines

  1. /* :bk=0 */
  2.  
  3. /****************************************************************/
  4. /*                                */
  5. /*    RxSlides.c                        */
  6. /*                                */
  7. /* Author: Dean Bandes                        */
  8. /*                                */
  9. /*    Based on Lee M. Robertson's "Dissolve" on Amicus 15    */
  10. /*    which is in turn based on an article in the Nov '86    */
  11. /*    Doctor Dobb's Journal by Mike Morton            */
  12. /*                                */
  13. /****************************************************************/
  14.  
  15. #include "exec/types.h"
  16. #include "exec/memory.h"
  17. #include "storage.h"
  18. #include "rxslib.h"
  19.  
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include "rxslides.h"
  23.  
  24. #define INTUITION_REV 29L
  25. #define GRAPHICS_REV 29L
  26.  
  27. struct    MsgPort  *CreatePort ();
  28. struct    MsgPort     *FindPort ();
  29. void         *GetMsg();
  30. void         *OpenLibrary();
  31.  
  32. ULONG            ctlcbit        = 0x1000;
  33. LONG            debug_level    = 21;
  34. LONG            failat        = 21;
  35. char            filename[80]    = "";
  36. struct    GfxBase        *GfxBase    = NULL;
  37. struct    IntuitionBase    *IntuitionBase    = NULL;
  38. BOOL            keep_going    = TRUE;
  39. ULONG            rexbit        = 0;
  40. SHORT            rmap_index    = 16;
  41. struct    RexxLib        *RexxSysBase    = NULL;
  42. struct    MsgPort        *Rxpt        = NULL;
  43. LONG            speed        = 1280;
  44. SHORT            transition    = 0;
  45.  
  46. #ifndef DEBUG
  47. LONG    _stack        = 4000;
  48. char   *_procname    = "RXSLIDES";
  49. LONG    _priority    = 0;
  50. LONG    _BackGroundIO    = 0;
  51. /*-h-    void    _main ()
  52.  */
  53.  
  54. void _main ()
  55. #else
  56. /*-h-    void    main ()
  57.  */
  58.  
  59. void main(argc,argv)
  60.  
  61. int argc;
  62. char **argv;
  63. #endif
  64.   {
  65.   extern    void    close_libs ();
  66.   extern    void    CloseReXXPort ();
  67. #ifdef DEBUG
  68.   extern    int    get_args ();
  69. #endif
  70.   extern    int    open_libs();
  71.   extern    int    OpenReXXPort ();
  72.  
  73.   struct RexxMsg *rmsg = NULL;
  74.   ULONG          signal = 0;
  75.   int           status;
  76.  
  77. #ifdef DEBUG
  78.   status = get_args (argc, argv);
  79.   if (status != STS_OK)
  80.     exit (STS_BAD_ARGS);
  81.  
  82.   if ( debug_level > 9 )
  83.     printf ("Returned from get_args\n");
  84. #endif
  85.  
  86.   if( speed < 100 )
  87.     speed = 1000;
  88.  
  89.   status = open_libs();            /* open the libraries */
  90.   if (status != STS_OK)
  91.     exit (STS_BAD_LIBS);
  92.  
  93.   status = OpenReXXPort ();
  94.   if ( status != STS_OK )
  95.     {
  96.     close_libs ();
  97.     exit (STS_NO_PORT);
  98.     }
  99.  
  100.   while (keep_going && (status < failat))
  101.     {
  102.     if ( debug_level > 10 )
  103.       signal = (ULONG) Wait (0xffffffff);
  104.     else
  105.       signal = (ULONG) Wait (ctlcbit | rexbit );
  106. #ifdef DEBUG
  107.     if ( debug_level > 5 )
  108.       printf ("Received signal %8lx\n", signal);
  109. #endif
  110.     if ( signal & ctlcbit )
  111.       {
  112. #ifdef DEBUG
  113.       if ( debug_level > 5 )
  114.     printf ("Looks like a ctrl-C, bye...\n");
  115. #endif
  116.       keep_going = FALSE;
  117.       break;
  118.       }
  119.     if ( signal & rexbit )
  120.       {
  121.       while (rmsg = (struct RexxMsg *) GetMsg (Rxpt))
  122.     {
  123. #ifdef DEBUG
  124.     if (debug_level > 15)
  125.       printf ("  rexx msg pointer = 0x%08lx\n", rmsg);
  126.     if (debug_level > 1)
  127.       printf ("Rexx: %s\n", rmsg->rm_Args[0]);
  128. #endif
  129.     status = Dissolve_dispatch (rmsg->rm_Args[0]);
  130. #ifdef DEBUG
  131.     if (debug_level > 15)
  132.       printf ("  replying, rexx msg pointer = 0x%08lx, status %d\n",
  133.           rmsg,
  134.           status);
  135. #endif
  136.     rmsg->rm_Result1 = status;
  137.     ReplyMsg (rmsg);
  138.     rmsg = NULL;
  139.     }
  140.       }
  141.     }
  142.  
  143.   CloseReXXPort ();
  144.   close_pic_window ();
  145.   close_libs ();
  146.   exit (STS_OK);
  147.   }
  148.  
  149. /*-h- OpenReXXPort ()
  150.  *
  151.  *    Open the message port for ReXX communication
  152.  *
  153.  *    Returns a status (0 = OK)
  154.  */
  155.  
  156. int    OpenReXXPort ()
  157.  
  158.   {
  159.   static    char    portname[12];
  160.  
  161.   int        portnum = 0;
  162.  
  163. #ifdef DEBUG
  164.   if ( debug_level > 9 )
  165.     printf ("Entered OpenReXXPort\n");
  166. #endif
  167.  
  168.   strcpy (portname, "SLIDES");
  169.  
  170. #ifdef DEBUG
  171.   if ( debug_level > 9 )
  172.     printf ("Trying message port name = %s\n", portname);
  173. #endif
  174.  
  175.   while (Rxpt = FindPort (portname))
  176.     {
  177.     if ( portnum > 26 )
  178.       {
  179. #ifdef DEBUG
  180.       if ( debug_level > 1 )
  181.     printf ("Ports SLIDES thru SLIDESZ in use\n");
  182. #endif
  183.       Rxpt = 0;
  184.       return (STS_NO_PORT);
  185.       }
  186.     portname[6] = 'A' + portnum++;
  187.     portname[7] = '\0';
  188. #ifdef DEBUG
  189.     if ( debug_level > 9 )
  190.       printf ("Trying message port name = %s\n", portname);
  191. #endif
  192.     }
  193.  
  194.   Rxpt = CreatePort (portname, 0);
  195.   if ( Rxpt )
  196.     {
  197.     rexbit = 1 << Rxpt->mp_SigBit;
  198. #ifdef DEBUG
  199.     if ( debug_level > 1 )
  200.       { 
  201.       printf ("Opened message port %s\n", portname);
  202.       printf ("  signal bit = %d\n", Rxpt->mp_SigBit);
  203.       printf ("  signal flag = %8lx\n", rexbit);
  204.       }
  205. #endif
  206.     return (STS_OK);
  207.     }
  208.   else
  209.     {
  210. #ifdef DEBUG
  211.     if ( debug_level > 1 )
  212.       printf ("CreatePort failed\n");
  213. #endif
  214.     return (STS_NO_PORT);
  215.     }
  216.   }
  217.  
  218. /*-h-    void    CloseReXXPort
  219.  *
  220.  *    Empties the ReXX port message queue and closes the port
  221.  */
  222.  
  223. void    CloseReXXPort ()
  224.  
  225.   {
  226.   struct RexxMsg *rmsg = NULL;
  227.  
  228.   while (rmsg = (struct RexxMsg *) GetMsg (Rxpt))
  229.     {
  230.     rmsg->rm_Result1 = STS_CLEANING_UP;
  231.     ReplyMsg (rmsg);
  232.     rmsg = 0;
  233.     }
  234.   DeletePort (Rxpt);
  235.   }
  236.  
  237. /*-h-    int    open_libs ()
  238.  *
  239.  *    open the required libraries
  240.  *
  241.  *    Returns status code (0 = OK)
  242.  */
  243.  
  244. int    open_libs()
  245.  
  246.   {
  247.   if( !(IntuitionBase = (struct IntuitionBase *)
  248.             OpenLibrary("intuition.library",INTUITION_REV)) )
  249.     {
  250. #ifdef DEBUG
  251.     printf("Can't open Intuition library\n");
  252. #endif
  253.     return(STS_BAD_LIBS);
  254.     }
  255.  
  256.   if( !(GfxBase = (struct GfxBase *)
  257.           OpenLibrary("graphics.library",GRAPHICS_REV)) )
  258.     {
  259. #ifdef DEBUG
  260.     printf("Can't open Graphics library\n");
  261. #endif
  262.     CloseLibrary(IntuitionBase);
  263.     return(STS_BAD_LIBS);
  264.     }
  265.  
  266.   if ( !(RexxSysBase = (struct RexxLib *)
  267.                OpenLibrary("rexxsyslib.library",(LONG) RXSVERS)) )
  268.     {
  269. #ifdef DEBUG
  270.     printf("Can't open Rexx library\n");
  271. #endif
  272.     CloseLibrary(GfxBase);
  273.     CloseLibrary(IntuitionBase);
  274.     return(STS_BAD_LIBS);
  275.     }
  276.   return (STS_OK);
  277.   }
  278.  
  279. /*-h-    void    close_libs ()
  280.  */
  281.  
  282. void    close_libs ()
  283.  
  284.   {
  285.   if( GfxBase )
  286.     CloseLibrary(GfxBase);
  287.   if( IntuitionBase )
  288.     CloseLibrary(IntuitionBase);
  289.   if( RexxSysBase )
  290.     CloseLibrary(RexxSysBase);
  291.   }
  292.  
  293. /*-h-    int    Dissolve_dispatch (rxcommand)
  294.  *
  295.  *    char    *rxcommand    command line received from ReXX
  296.  */
  297.  
  298. int    Dissolve_dispatch (rxcommand)
  299.  
  300. char *rxcommand;
  301.  
  302.   {
  303.   char *command;
  304.   char *str2;
  305.   int    status = STS_OK;
  306.   int    delay_param = 0;
  307.   char  cbuff[128];
  308.   char    pbuff[128];
  309.  
  310. #ifdef DEBUG
  311.   if ( debug_level > 15 )
  312.     printf ("Entered Dissolve_dispatch with command %s\n", rxcommand);
  313. #endif
  314.   
  315.   command = rxcommand;
  316.  
  317.   str2    = cbuff;
  318.   *str2   = '\0';
  319.  
  320.   while (*command && isspace (*command))
  321.     command++;
  322.  
  323.   while (*command && ( ! isspace (*command)))
  324.     *str2++ = *command++;
  325.  
  326.   *str2 = '\0';
  327.  
  328.   str2  = pbuff;
  329.   *str2 = '\0';
  330.  
  331.   while (*command && isspace (*command))
  332.     command++;
  333.  
  334.   while (*command && ( ! isspace (*command)))
  335.     *str2++ = *command++;
  336.  
  337.   *str2 = '\0';
  338.  
  339. #ifdef DEBUG
  340.   if (debug_level > 15 )
  341.     printf ("Parsed as command %s, parameter %s\n", cbuff, pbuff);
  342. #endif
  343.  
  344.   if ( 0 == stricmp (cbuff, "show"))
  345.     {
  346.     strcpy (filename, pbuff);
  347.     status = show_pic (pbuff, speed, transition);
  348.     }
  349.   else if ( 0 == stricmp (cbuff, "speed"))
  350.     speed = atoi (pbuff);
  351.   else if ( 0 == stricmp (cbuff, "wait"))
  352.     {
  353.     delay_param = atoi (pbuff);
  354.     Delay ( delay_param );
  355.     }
  356. #ifdef DEBUG
  357.   else if ( 0 == stricmp (cbuff, "debug"))
  358.     debug_level = atoi (pbuff);
  359. #endif
  360.   else if ( 0 == stricmp (cbuff, "failat"))
  361.     {
  362.     failat = atoi (pbuff);
  363.     if ( failat < 1 )
  364.       failat = 1;
  365.     }
  366.   else if ( 0 == stricmp (cbuff, "index"))
  367.     {
  368.     rmap_index = atoi (pbuff);
  369.     if ( rmap_index < 2 )
  370.       rmap_index = 2;
  371.     if ( rmap_index > 32 )
  372.       rmap_index = 32;
  373.     }
  374.   else if ( 0 == stricmp (cbuff, "trans"))
  375.     {
  376.     if ( 0 == stricmp (pbuff, "zap"))
  377.       transition = DM_ZAP;
  378.     else if ( 0 == stricmp (pbuff, "twipe"))
  379.       transition = DM_TWIPE;
  380.     else if ( 0 == stricmp (pbuff, "bwipe"))
  381.       transition = DM_BWIPE;
  382.     else if ( 0 == stricmp (pbuff, "lwipe"))
  383.       transition = DM_LWIPE;
  384.     else if ( 0 == stricmp (pbuff, "rwipe"))
  385.       transition = DM_RWIPE;
  386.     else if ( 0 == stricmp (pbuff, "vblind"))
  387.       transition = DM_VBLIN;
  388.     else if ( 0 == stricmp (pbuff, "dissolve"))
  389.       transition = DM_DISSO;
  390.     else if ( 0 == stricmp (pbuff, "fade"))
  391.       transition = DM_DISSO;
  392.     else
  393.       transition = atoi (pbuff);
  394.  
  395.     if ( transition < 0 )
  396.       transition = 0;
  397.     if ( transition > MAX_TRANSITION )
  398.       transition %= (MAX_TRANSITION + 1);
  399.     }
  400.   else if ( 0 == stricmp (cbuff, "front"))
  401.     pic_front ();
  402.   else if ( 0 == stricmp (cbuff, "back"))
  403.     pic_back ();
  404.   else if ( 0 == stricmp (cbuff, "close"))
  405.     close_pic_window ();
  406.   else if ( 0 == stricmp (cbuff, "exit"))
  407.     keep_going = 0;
  408.   else if ( 0 == stricmp (cbuff, "quit"))
  409.     keep_going = 0;
  410.   else
  411.     status = STS_UNKNOWN_CMD;
  412.   return (status);
  413.   }
  414.